<template>
	<view class="home">
		<navbar>自定义头部</navbar>
		<tab :list="tablist" @tab='tab' :tabIndex="tabIndex"></tab>
		<view class="home-list">
			<list :tab="tablist" @change="change" :activeIndex="activeIndex"></list>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '首页',
				imgUrl: '',
				tablist: [],
				tabIndex: 0,
				activeIndex: 0
			}
		},
		onLoad() {
			uni.$on('labelChange', (res) => {
					this.tabIndex = 0;
					this.activeIndex = 0
					this.tablist = []
					this.getLabel()
				})
				this.getLabel()
		},
		methods: {
			tab({
				data,
				index
			}) {
				this.activeIndex = index;
				console.log(data.name, index)
			},
			change(current) {
				this.tabIndex = current;
				this.activeIndex = current
			},
			getLabel() {
				// this.$api.get_list().then(res => {
				// 	console.log(res)
				// })

				this.$api.get_label({
					name: 'get_label'
				}).then((res) => {
					const {
						data
					} = res;
					data.unshift({
						name: "全部"
					})
					this.tablist = data
				})
			},
			oepnCloud() {
				uniCloud.callFunction({
					name: "getlist",
					data: {
						name: "tom"
					},
					success(res) {
						console.log(res);
					},
					fail(res) {
						console.log(res);
					}
				})
			},
			uploadImage() {
				let self = this;
				uni.chooseImage({
					count: 1,
					success(res) {
						const path = res.tempFilePaths[0];
						uniCloud.uploadFile({
							filePath: path,
							cloudPath: "testupload111.png",
							success(res) {
								self.imgUrl = res.fileID;
								console.log("路劲:" + self.imgUrl);
							},
							fail(res) {
								console.log(res);
							}
						})
					},
					fail(res) {
						console.log(res)
					}
				})
			}
		},

	}
</script>

<style lang="scss">
	page {
		height: 100%;
		display: flex;
	}

	.home {
		display: flex;
		flex-direction: column;
		flex: 1;
		border: red 1px solid;
		overflow: hidden;

		.home-list {
			flex: 1;
			box-sizing: border-box;
			height: 100%;
		}
	}
</style>
